package com.strelitzia.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.strelitzia.entity.NotificationEntity;

import com.strelitzia.filter.CorsFilter;

import com.strelitzia.service.NotificationService;
import com.strelitzia.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @create 2024/1/16 14:22
 */

@RestController
@RequestMapping("notification")
public class NotificationController {
    @Autowired
    NotificationService notificationService;

    @GetMapping()
    public ResultVo list() {
        ResultVo resultVo = new ResultVo();
        try {
            resultVo.setData(notificationService.getList());
        } catch (Exception e) {
            resultVo.setMsg("服务器错误");
            resultVo.setCode(1);
        }
        return resultVo;

    }

    @GetMapping("/visitor")
    public ResultVo getVisitor() {
        ResultVo resultVo = new ResultVo();
        try {
            resultVo.setData(notificationService.getVisitor());
        } catch (Exception e) {
            resultVo.setMsg("服务器错误");
            resultVo.setCode(1);
        }
        return resultVo;
    }

    @GetMapping("/count")
    public Integer count() {
        return notificationService.count(new QueryWrapper<NotificationEntity>()
                .eq("receiver", CorsFilter.loginUserId.get()).eq("no_read", 0));
    }
}
